package com.ccy.utils;

public final class Log {

	private static long oldTime = 0;
	
	private Log() {
	}

	// info
	public static void i(String msg) {
		i(null, msg, null);
	}

	public static void i(String msg, Throwable e) {
		i(null, msg, e);
	}

	public static void i(String tag, String msg) {
		i(tag, msg, null);
	}

	public static void i(String tag, String msg, Throwable e) {
		StringBuffer sBuffer = new StringBuffer(128);
		if (tag != null) {
			sBuffer.append("[")//
					.append(tag)//
					.append("] ");
		}
		
		// time
		if (oldTime == 0) {
			sBuffer.append(oldTime);
			oldTime = System.currentTimeMillis();
		} else {
			long newTime = System.currentTimeMillis();
			sBuffer.append(newTime - oldTime);
			oldTime = newTime;
		}
		
		// msg
		sBuffer.append("[")//
				.append(msg)//
				.append("]");
		
		// exception
		if (e != null) {
			sBuffer.append("\n")//
					.append(e.toString());
		}
		System.out.println(sBuffer.toString());
	}

	// error
	public static void e(String msg) {
		e(null, msg, null);
	}

	public static void e(String msg, Throwable e) {
		e(null, msg, e);
	}

	public static void e(String tag, String msg) {
		e(tag, msg, null);
	}

	public static void e(String tag, String msg, Throwable e) {
		StringBuffer sBuffer = new StringBuffer(128);
		if (tag != null) {
			sBuffer.append("[")//
					.append(tag)//
					.append("] ");
		}
		sBuffer.append(msg);
		if (e != null) {
			sBuffer.append("\n")//
					.append(e.toString());
		}
		System.err.println(sBuffer.toString());
	}
}
